package com.kayo.specimen.config;


import com.alibaba.fastjson.JSON;
import com.kayo.specimen.utility.PagingInfo;
import com.kayo.specimen.utility.StringUtils;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.interceptor.SimpleKey;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Map;
import java.util.StringJoiner;

@Component
public class MyCacheKeyGenerator implements KeyGenerator {

    @Override
    public Object generate(Object target, Method method, Object... params) {
        StringJoiner id=new StringJoiner(".");

        id.add(method.getName());
        for (Object obj : params) {
            if(obj==null)
                continue;

            if (obj instanceof PagingInfo) {
                PagingInfo pagingInfo = (PagingInfo) obj;
                id.add(Integer.toString(pagingInfo.getPage()));
                id.add(Integer.toString(pagingInfo.getLimit()));
                id.add(pagingInfo.getSort());
                id.add(pagingInfo.getOrder());
            } else {
                id.add(obj.toString());
            }
        }

        return (id.toString());

    }

}
